package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;

import java.util.Objects;

/**
 * 计量方式：计量方式选择总量控制时，联动展示使用总量
 */
public class MeasurementWayAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {
    @Override
    public void set(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        super.set(attr, inst, value, data);
        //使用总量
        KiteAttr useTotalAttr = null;
        if(KiteStringUtils.isNotBlank(inst.getSpecId())&&KiteStringUtils.equalsAny(inst.getSpecId(),"10003958","65040207")){//智慧信息
            useTotalAttr = inst.getAttr("200001083");
        }else if(KiteStringUtils.isNotBlank(inst.getSpecId())&&KiteStringUtils.equals(inst.getSpecId(),"10003959")){//三网信息
            useTotalAttr = inst.getAttr("200001180");
        }

        if (Objects.isNull(useTotalAttr)) {
            return;
        }
        if ("100000774".equals(attr.getValue())) {
            //计量方式为是,使用总量展示且必填
            useTotalAttr.setIsNull(LocalKeyConsts.IFTRUE_F);
            useTotalAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_D);
        }
        else {
            //计量方式为否， 使用总量不展示
            useTotalAttr.setIsNull(LocalKeyConsts.IFTRUE_T);
            useTotalAttr.setShowType(LocalKeyConsts.PROD_ATTR_SHOW_TYPE_E);
        }


    }


}
